import win32com.client
import time

dm = win32com.client.Dispatch('dm.dmsoft')
print(dm.Ver())
# string EnumWindow(parent,title,class_name,filter)
parent_hwnd = dm.EnumWindow(0, 'kaopu001_tiantianplayer_opengl_wndWindow', 'Qt5QWindowIcon', 1+2)
hwnd = int(parent_hwnd.split(',')[0]) #dm.FindWindowEx((parent_hwnd.split(',')[0]), 'subWin', 'sub')

print(parent_hwnd, hwnd)

# long BindWindow(hwnd,display,mouse,keypad,mode)
bind_ret = dm.BindWindow(hwnd, 'dx2', 'windows', 'windows', 1)
print('BindWindow:\t', bind_ret)

# long GetWindowRect(hwnd,x1,y1,x2,y2)
ret2,x1,y1,x2,y2 = dm.GetWindowRect(hwnd, 0, 0, 0, 0)
print(x1,y1,x2,y2)

print(dm.MoveTo(370, 300))
print(dm.LeftDown())
dm.MoveR(50,25)
time.sleep(0.2) # 不能用dm.Delay(200)，会导致后台键鼠失效
dm.LeftUp()


# long Capture(x1, y1, x2, y2, file)
print('Capture', dm.Capture(0,0,1024,600, 'D:/screen1.bmp'))

if(bind_ret == 1):
    print('UnBindWindow:\t', dm.UnBindWindow())



